package org.myOrg.spetrum.GUI;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ContentPanel extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	private ResultShowPanel showPanel;
	private ToolBar toolBar;
	private BugInsertPanel bugPanel;
	JPanel content;
	
	public  ContentPanel(){
		build();
		addListener();
	}
	public void build(){
		content = new JPanel();
		bugPanel = new BugInsertPanel();
		toolBar = new ToolBar();
		showPanel = new ResultShowPanel();
		
		content.setLayout(new CardLayout());
		content.add(showPanel,"showPanel");
		content.add(bugPanel,"bugPanel");
				
		this.setLayout(new BorderLayout());
		this.add(toolBar, BorderLayout.NORTH);
		this.add(content, BorderLayout.CENTER);		

	}
	public void addListener(){
		this.toolBar.getViewChange().addActionListener(new ChangeViewListener());
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame();
		frame.setSize(560, 200);
		frame.getContentPane().add(new ContentPanel());
		frame.setVisible(true);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
	
	class ChangeViewListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if(e.getActionCommand().equals(ToolBar.BUGINSERT)){
				((JButton)e.getSource()).setText(ToolBar.RUNINGVIEW);
				((CardLayout)content.getLayout()).show(content, "bugPanel");	
			}
			else{
				((JButton)e.getSource()).setText(ToolBar.BUGINSERT);
				((CardLayout)content.getLayout()).show(content, "showPanel");
			}
		}
		
	}
	
}
